package com.pi.message;


import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class SmsSender {
    public static void main(String[] args) {
        // 设置访问密钥
        String accessKeyId = "LTAI5tDopLDAtNtPySLiHbcT";
        String accessKeySecret = "wtmHDOdobHeqWVGD9JJ5GWqxqzvrA6";
        String studentName = null;

        // 创建 DefaultAcsClient 实例
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);

        // 构造请求
        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers("18012831178");
        request.setSignName("蒋明喆的博客");
        request.setTemplateCode("SMS_464085232");
        request.setTemplateParam("{\"name\":\""+studentName+"\"}"); // 这里填写短信的内容

        try {
            // 发送短信
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println("短信发送成功，短信ID：" + response.getRequestId());
        } catch (ClientException e) {
            System.out.println("短信发送失败：客户端错误 " + e.getMessage());
        }
    }
}
